package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.GlDetail;
import com.ruoyi.system.service.IGlDetailService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 凭证分录Controller
 * 
 * @author ruoyi
 * @date 2025-09-15
 */
@Controller
@RequestMapping("/system/glDetail")
public class GlDetailController extends BaseController
{
    private String prefix = "system/glDetail";

    @Autowired
    private IGlDetailService glDetailService;

    @RequiresPermissions("system:glDetail:view")
    @GetMapping()
    public String glDetail()
    {
        return prefix + "/glDetail";
    }

    /**
     * 查询凭证分录列表
     */
    @RequiresPermissions("system:glDetail:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GlDetail glDetail)
    {
        startPage();
        List<GlDetail> list = glDetailService.selectGlDetailList(glDetail);
        return getDataTable(list);
    }

    /**
     * 导出凭证分录列表
     */
    @RequiresPermissions("system:glDetail:export")
    @Log(title = "凭证分录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GlDetail glDetail)
    {
        List<GlDetail> list = glDetailService.selectGlDetailList(glDetail);
        ExcelUtil<GlDetail> util = new ExcelUtil<GlDetail>(GlDetail.class);
        return util.exportExcel(list, "凭证分录数据");
    }

    /**
     * 新增凭证分录
     */
    @RequiresPermissions("system:glDetail:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存凭证分录
     */
    @RequiresPermissions("system:glDetail:add")
    @Log(title = "凭证分录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GlDetail glDetail)
    {
        return toAjax(glDetailService.insertGlDetail(glDetail));
    }

    /**
     * 修改凭证分录
     */
    @RequiresPermissions("system:glDetail:edit")
    @GetMapping("/edit/{pkDetail}")
    public String edit(@PathVariable("pkDetail") String pkDetail, ModelMap mmap)
    {
        GlDetail glDetail = glDetailService.selectGlDetailByPkDetail(pkDetail);
        mmap.put("glDetail", glDetail);
        return prefix + "/edit";
    }

    /**
     * 修改保存凭证分录
     */
    @RequiresPermissions("system:glDetail:edit")
    @Log(title = "凭证分录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GlDetail glDetail)
    {
        return toAjax(glDetailService.updateGlDetail(glDetail));
    }

    /**
     * 删除凭证分录
     */
    @RequiresPermissions("system:glDetail:remove")
    @Log(title = "凭证分录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(glDetailService.deleteGlDetailByPkDetails(ids));
    }
}
